#include "ohos_init.h"
#include "cmsis_os2.h"
#include "/home/openharmony/base/iot_hardware/peripheral/interfaces/kits/iot_gpio.h"
#include "gpio_led2.h"

#define LED_TASK_GPIO1 7
#define LED_TASK_GPIO2 8
#define LED_INTERVAL_TIME 30
#define LED_TASK_STACK_SIZE 1024
#define LED_TASK_PRIO 25

int isOpenLed = 1;

static void LedTask1(void){
    while(1){
        //一个led灯常亮
        // IoTGpioSetOutputVal(LED_TASK_GPIO1,1);
        // printf("LED_TASK_GPIO-----1 work\n");
        //另一个led灯不停闪
        if(isOpenLed == 1){
            IoTGpioSetOutputVal(LED_TASK_GPIO2,isOpenLed);
            printf("LED_TASK_GPIO-----2 work isOpenLed ===== %d\n",isOpenLed);
            sleep(1);
            IoTGpioSetOutputVal(LED_TASK_GPIO2,!isOpenLed);
            sleep(1);
        }
    }
}

static void LedExampleEntry(void){
    osThreadAttr_t attr;
    //初始化
    IoTGpioInit(LED_TASK_GPIO1);
    IoTGpioSetDir(LED_TASK_GPIO1,IOT_GPIO_DIR_OUT);
    IoTGpioInit(LED_TASK_GPIO2);
    IoTGpioSetDir(LED_TASK_GPIO2,IOT_GPIO_DIR_OUT);

    attr.name = "LedTask1";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = LED_TASK_STACK_SIZE;
    attr.priority = LED_TASK_PRIO;
    if(osThreadNew((osThreadFunc_t)LedTask1,NULL,&attr) == NULL){
        printf("[LedExampleEntry] Falied to create LedTask1!\n");
    }
}

SYS_RUN(LedExampleEntry);